//
//  String+Extension.swift
//  SDAutoWeibo
//
//  Created by 刘健 on 16/3/31.
//  Copyright © 2016年 Clemmie. All rights reserved.
//

import UIKit

extension String {
    
    //截取字符串 用正则表达式
    func rangeString () -> String {
        //截取样式
        let string = ">(.*?)<"
        
        let regular = try! NSRegularExpression(pattern: string, options: NSRegularExpressionOptions.DotMatchesLineSeparators)
        
        let result = regular.firstMatchInString(self, options: NSMatchingOptions(rawValue: 0), range: NSRange(location: 0, length: self.characters.count))
        
        //配到的范围数
        let count = result?.numberOfRanges ?? 0
        
        if count > 1 {
            let range = result?.rangeAtIndex(1)
            return (self as NSString).substringWithRange(range!)
        }
        return "未知来源"
    }
    
    
    
    
}
